import queryString from 'query-string';
import { Result } from '@/interface/common.interface';

export function getTableData(
  data: { current: number; pageSize: number },
  formData: object,
): Promise<Result<Item>> {
  const query = queryString.stringify({ ...data, ...formData });

  return fetch(`https://randomuser.me/api?results=55&${query}`)
    .then((res) => res.json())
    .then((res) => {
      res.results.forEach(
        (item: any, index: number) =>
          (item.code = (data.current - 1) * data.pageSize + index),
      );
      return {
        total: res.info.results,
        list: res.results,
      };
    });
}
